/* Layer 2 definitions (application layer).
 * 
 * Defines all the MIN setup for the application, selecting IDs to be used
 * and how to pack and unpack signal data and commands.
 * 
 * Author: Ken Tindell
 * Copyright (c) 2014-2015 JK Energy Ltd.
 * Licensed under MIT License.
 */ 

#ifndef LAYER2_H_
#define LAYER2_H_


#include <iostream>
#include <vector>
#include <fstream>
#include <stdio.h>
#include <string>
#include <string.h>


using namespace std;



/* Command frames from the host */
#define MIN_ID_MOVE_CMD					(0x20u)			/* Layer 1 frame; Set requested motor position */
#define MIN_ID_SET_DUTY     			(0x21u)			/* Layer 1 frame; Set requested motor position */
#define MIN_ID_GET_DUTY     			(0x22u)

/* Layer 1 frame; Temperature and humidity sensor values */
#define MIN_ID_ENVIRONMENT				(0x30U)	
#define TURN_ID_COMPLETE				(0xacU)  //��ת���ɵ�id
#define TURN_COMPLETE					(0x6bU)  //��ת����

#define RadarConfiguration 0x200
#define RadarFeedback      0x400
#define RadarStatus        0x60A
#define TargetStatus       0x70B
#define TargerInformation  0x70C
#define MIN_ID_RADAR  0x32
extern int int_SerialFD;

/* Set up communications */
int init_uart(string uart_port, int & device_id);

/* Poll the incoming uart to send bytes into MIN layer 1 */
void poll_rx_bytes(void);
/* Functions to take application data and send to host */

void* pthread_uart_monitor(void*);

void init_min(void);

void motion(int16_t speed_enable,int16_t target_speed,int16_t dir_enable,int16_t target_angle,int16_t  target_dir);

void update_radar(uint8_t m_id, uint8_t m_buf[], uint8_t m_control);
void * pthread_ladar(void *);
void get_ladar_distance();


typedef struct {

    uint32_t left_speed;
    uint32_t right_speed;
    uint32_t motor_speed;
    uint32_t car_angle;
    uint16_t motor_pulse;

    float imu_pitch;
    float imu_roll;
    float imu_yaw;

}small_car_pulse;


typedef struct
{
    uint8_t Radar_ID;
    uint8_t Radar_Mode;
    uint8_t Radar_RollCount;
    uint8_t Radar_Output_Type;
    uint8_t Radar_Mount_Dir;
}	RadarStatusTypeDef;


typedef struct
{
    uint8_t Cluster_Index;
    uint8_t Radar_RollCount;
    uint8_t Cluster_SNR;
    int8_t Cluster_Azimuth;
    float Cluster_RCSValue;
    float Cluster_Range;
    float  Cluster_Vrel;
}	TargeInfoTypeDef;



typedef enum {
 RecTargetStatus   =0,
 RecInTargetInfo   =1,
 TargetDetectOver  =2
}NextStep;


typedef struct
{
    uint8_t NumOfCluster;
    uint8_t Radar_RollCount;
    TargeInfoTypeDef TargeInfo[8];
    uint8_t nextstep;
}TargetStatusTypeDef;


#endif /* LAYER2_H_ */
